package com.itfitness.mchart.fragment;

import android.content.Intent;

import com.hyphenate.EMMessageListener;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMConversation;
import com.hyphenate.chat.EMMessage;
import com.hyphenate.chat.adapter.EMAConversation;
import com.hyphenate.easeui.EaseConstant;
import com.hyphenate.easeui.EaseUI;
import com.hyphenate.easeui.ui.EaseContactListFragment;
import com.hyphenate.easeui.ui.EaseConversationListFragment;
import com.itfitness.mchart.activity.ChartActivity;

import java.util.List;

/**
 * @ProjectName: MChart
 * @Package: com.itfitness.mchart.fragment
 * @ClassName: ConversationListFragment
 * @Description: java类作用描述 ：会话列表页面
 * @Author: 作者名：lml
 * @CreateDate: 2019/4/24 9:29
 * @UpdateUser: 更新者：
 * @UpdateDate: 2019/4/24 9:29
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */

public class ConversationListFragment extends EaseConversationListFragment implements EaseConversationListFragment.EaseConversationListItemClickListener,EMMessageListener {
    @Override
    protected void initView() {
        super.initView();
        hideTitleBar();
        setConversationListItemClickListener(this);
        conversationList.clear();
        EMClient.getInstance().chatManager().addMessageListener(this);//监听消息的接收
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
//        记得在不需要的时候移除listener，如在activity的onDestroy()时
        EMClient.getInstance().chatManager().removeMessageListener(this);
    }

    @Override
    public void onListItemClicked(EMConversation conversation) {
        //点击会话列表
        Intent intent = new Intent(getContext(), ChartActivity.class);
        intent.putExtra(EaseConstant.EXTRA_USER_ID,conversation.conversationId());
        if (conversation.getType() == EMConversation.EMConversationType.GroupChat){
            intent.putExtra(EaseConstant.EXTRA_CHAT_TYPE,EaseConstant.CHATTYPE_GROUP);
        }
        startActivity(intent);
    }

    @Override
    public void onMessageReceived(List<EMMessage> messages) {
        //收到消息的时候进行刷新
//        EaseUI.getInstance().getNotifier().notify(messages);
        refresh();
    }

    @Override
    public void onCmdMessageReceived(List<EMMessage> messages) {

    }

    @Override
    public void onMessageRead(List<EMMessage> messages) {

    }

    @Override
    public void onMessageDelivered(List<EMMessage> messages) {

    }

    @Override
    public void onMessageRecalled(List<EMMessage> messages) {

    }

    @Override
    public void onMessageChanged(EMMessage message, Object change) {

    }
}
